package gold.digger;

import gold.utils.InputUtil;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC504 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String convertToBase7(int num) {
            if (0 == num) return "0";
            boolean flag = num < 0;
            num = Math.abs(num);
            StringBuilder ans = new StringBuilder();
            int i = 14;
            while (num >= 0 && i >= 0) {
                long curDivisor = (long) (Math.pow(7, i--));
                long curBit = num / curDivisor;
                if (0 == curBit && ans.length() <= 0) continue;
                ans.append(curBit);
                num %= curDivisor;
            }

            return (flag ? "-" : "") + ans.toString();
        }
    }

    public void run() {
        System.out.println(new Solution().convertToBase7(100));
        System.out.println(new Solution().convertToBase7(-7));
    }

    public static void main(String[] args) throws Exception {
        LC504 an = new LC504();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
